package avicit.cbb.billdefine.service.api;

import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class BillDefineDynamicServiceApi {


    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/BillDefineDynamicService/BillDefineDynamicServiceRest";

    @Autowired
    private RestClient restClient;

    /**
     *获取动态DETAIL页面HTML
     * @param editList
     * @param mapCode
     * @param dynamicMap
     * @return
     */
    public String getDynamicDetailHtml(List<Map<String, Object>> editList, Map<String, Map<String, String>> mapCode, Map<String, Object> dynamicMap) {
        String url = BASE_PATH + "/getDynamicDetailHtml";
        Map<String,Object> map = new HashMap<>();
        map.put("editList",editList);
        map.put("mapCode",mapCode);
        map.put("dynamicMap",dynamicMap);
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *获取datagrid的html
     * @param param
     * @return
     */
    public String getDatagridHtml(Map<String, Object> param) {
        Map<String,Object> resMaps = new HashMap<>();
        resMaps.put("param",param);
        String url = BASE_PATH + "/getDatagridHtml/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }





//    public String getDynamicDetailHtml(List<Map<String, Object>> formShowList,Map<String, Map<String, String>> mapCode,Map<String, Object> param) {
//        Map<String,Object> resMaps = new HashMap<>();
//        resMaps.put("formShowList",formShowList);
//        resMaps.put("mapCode",mapCode);
//        resMaps.put("param",param);
//        String url = BASE_PATH + "/getDynamicDetailHtml/v1";
//        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<String>>() {
//        });
//        return RestClientUtils.getResponseBody(responseMsg);
//    }


    /**
     *获取动态DETAIL页面HTML
     * @param formShowList
     * @param mapCode
     * @param param
     * @return
     */
    public String getDynamicDetailHtmlByInput(List<Map<String, Object>> formShowList,Map<String, Map<String, String>> mapCode,Map<String, Object> param) {
        Map<String,Object> resMaps = new HashMap<>();
        resMaps.put("formShowList",formShowList);
        resMaps.put("mapCode",mapCode);
        resMaps.put("param",param);
        String url = BASE_PATH + "/getDynamicDetailHtmlByInput/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *获取动态ADD页面HTML
     * @param formShowList
     * @param mapCode
     * @param param
     * @return
     */
    public String getDynamicAddHtml(List<Map<String, Object>> formShowList,Map<String, Map<String, String>> mapCode,Map<String, Object> param) {
        Map<String,Object> resMaps = new HashMap<>();
        resMaps.put("formShowList",formShowList);
        resMaps.put("mapCode",mapCode);
        resMaps.put("param",param);
        String url = BASE_PATH + "/getDynamicAddHtml/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *获取动态EDIT页面HTML
     * @param formShowList
     * @param mapCode
     * @param param
     * @return
     */
    public String getDynamicEditHtml(List<Map<String, Object>> formShowList,Map<String, Map<String, String>> mapCode,Map<String, Object> param) {
        Map<String,Object> resMaps = new HashMap<>();
        resMaps.put("formShowList",formShowList);
        resMaps.put("mapCode",mapCode);
        resMaps.put("param",param);
        String url = BASE_PATH + "/getDynamicEditHtml/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *获取动态SEARCH页面HTML
     * @param formShowList
     * @param mapCode
     * @param param
     * @return
     */
    public String getDynamicSearchHtml(List<Map<String, Object>> formShowList,Map<String, Map<String, String>> mapCode,Map<String, Object> param) {
        Map<String,Object> resMaps = new HashMap<>();
        resMaps.put("formShowList",formShowList);
        resMaps.put("mapCode",mapCode);
        resMaps.put("param",param);
        String url = BASE_PATH + "/getDynamicSearchHtml/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     *通过配置文件获取附件相应字段
     * @return
     */
    public List<Map<String, Object>> getAttachmentClassMapByProperties() {
        Map<String,Object> resMaps = new HashMap<>();
        String url = BASE_PATH + "/getAttachmentClassMapByProperties/v1";
        ResponseMsg<List<Map<String, Object>>> responseMsg = restClient.doPost(SERVICE_CODE, url, resMaps, new ParameterizedTypeReference<ResponseMsg<List<Map<String, Object>>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }





}
